package com.comtop.springboot.templet.modules.sys.redis;

import com.comtop.springboot.templet.common.service.RedisService;
import com.comtop.springboot.templet.modules.sys.entity.SysConfigEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 系统配置Redis
 *
 * @author wangjiafang
 * @version 1.0
 * @since 2017/7/18 21:08
 */
@Component
public class SysConfigRedis {
    @Autowired
    private RedisService redisService;

    private final String sysConfigKeyPrefix = "sys:config:";

    public void saveOrUpdate(SysConfigEntity config) {
        if(config == null){
            return ;
        }
        String key =sysConfigKeyPrefix+config.getKey();
        redisService.set(key, config);
    }

    public void delete(String configKey) {
        String key =sysConfigKeyPrefix+configKey;
        redisService.delete(key);
    }

    public SysConfigEntity get(String configKey){
        String key =sysConfigKeyPrefix+configKey;
        return redisService.get(key, SysConfigEntity.class);
    }
}
